<extend name="public/form"/>
<block name="css"></block>
<block name="content">
    <div class="layui-card-header ">
        <span class="layui-breadcrumb">
          <a href="/admin" target="_blank">首页</a>
          <a href="javascript:;">常规配置</a>
          <a href="javascript:;" onclick="parent.xadmin.add_tab('采集任务','{:url('index')}')">采集任务</a>
          <a><cite>编辑采集任务</cite></a>
        </span>
        <a class="layui-btn layui-btn-sm" style="line-height:1.6em;margin-top:3px;float:right"
           href="javascript:location.replace(location.href);" title="刷新">
            <i class="layui-icon layui-icon-refresh-3" style="line-height:30px"></i></a>
    </div>
    <div class="layui-card-body layui-tab">
        <form id="form1" class="layui-form">
            <input type="hidden" name="id" value="{$data['id']}">
            <div class="layui-form-item">
                <label class="layui-form-label">采集任务名</label>
                <div class="layui-input-block">
                    <input type="text" name="name" lay-verify="required" lay-reqtext="请填写采集任务名！"
                           placeholder="请输入采集任务名" autocomplete="off" class="layui-input " value="{$data['name']}">
                </div>
            </div>            

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" lay-filter="add">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>
</block>
<block name="js">
    <script>
        layui.use(['jquery', 'form', 'layer', 'element'], function () {
            var $ = layui.jquery,
                form = layui.form,
                layer = layui.layer;
            layui.element.render();
            form.on('submit(add)', function (data) {
                let send_json = data.field;
                let url='/admin/collect_task/edit/id/'+send_json.id;
                delete send_json.id;
                $.ajax({
                    url: url,
                    method: 'post',
                    data: send_json,
                    dataType: 'JSON',
                    success: function (res) {
                        if (res.code == 0) {
                            layer.alert(res.msg, {
                                icon: 1
                            }, function () {
                                location.reload();
                            });
                        } else {
                            layer.msg(res.msg, {icon: 5});
                        }

                    },
                    error: function (data) {
                        layer.msg('服务器繁忙', {icon: 5});
                    }
                });
                return false;
            });
        });
    </script>
</block>